const path = require('path');
const fs = require('fs')
const vue = require('@vitejs/plugin-vue')

module.exports = ({ command,mode }) => {
// 判断是生产环境还是开发环境
 const VITE_APP_IS_SERVE = command === 'serve' ? true : false;

  return {
    plugins: [vue()],
    // 支持别名
    resolve:{
      alias: {
        '/@': path.resolve(__dirname, 'src'),
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          // TODO css变量暂时使用scss，后期会改成css3变量
          additionalData: content => {
            // content = content.replace(/\/@\/assets/g,'/src/assets')
            return `
            $--color-blue: #1890ff;
            $--color-red: #FF4D4F;
            $--vab-margin: 24px;
            $--vab-padding: 24px;
            $--vab-header-height: 48px;
          ${content}`
          },
        },
      },
    },
    define: {
      VITE_APP_IS_SERVE,
    },
    server: {
      open: false, // https://vitejs.dev/config/#server-open
      proxy: {
        // https://vitejs.dev/config/#server-proxy
        [VITE_APP_BASE_API]: {
          target: VITE_APP_BUILD_BASE_API,
          changeOrigin: true,
          rewrite: path => path.replace(new RegExp(`^${VITE_APP_BASE_API}`), ''),
        },
        [VITE_APP_FILE_SERVICE_API]: {
          target: VITE_APP_BUILD_FILE_SERVICE_API,
          changeOrigin: true,
          rewrite: path => path.replace(new RegExp(`^${VITE_APP_FILE_SERVICE_API}`), ''),
        },
      },
    },
    build:{
      terserOptions:{
        compress:{
          drop_console: true
        }
      },
    }
  }
}